<template>
	<div class="authors">
		<div class="authors_details">
			<p class="name">
				<b class="shu"></b>
				<span>{{obj.name}}简介</span>
			</p>
			<p class="content">{{obj.desc}}</p>
		</div>
		<div class="authors_details">
			<p class="name">
				<b class="shu"></b>
				<span>{{obj.name}}诗文</span>
			</p>
			<div class="potry_name" v-for="(item,index) in list" @click="poetrydetail(item)">
				<p class="name">《{{item.title}}》</p>
			</div>
			<view class="more">
				<span>{{moreText}}</span>
			</view>
		</div>
	</div>
</template>

<script>
	export default{
		data(){
			return{
				obj:{},
				pageSize:10,
				pageNumber:0,
				list:[],
				totalPage:0,
				moreText:'已加载全部'
			}
		},
		onLoad(options) {
			this.obj=JSON.parse(options.obj)
			if(this.obj.desc==''){
				this.getAuthos(this.obj.name)
			}else{
				this.obj=Object.assign(this.obj)
				uni.setNavigationBarTitle({
					title:this.obj.name+'简介'
				})
				this.getList(this.obj.id)
			}
			
			
		},
			onReachBottom(){
				this.getAuthors()
			},
			onShareAppMessage(res) {
					wx.showShareMenu({
					     withShareTicket: true,
					     menus: ['shareAppMessage', 'shareTimeline']
					    })
					return{
							title:this.obj.name+'简介',
							imageUrl:'https://www.leedong.top/img/11556.png',
							path:'/pages/authorsdetail/index?obj='+JSON.stringify(this.obj)
					}
					
					},
					//2.分享到朋友圈
			onShareTimeline(){
			
				return {
					title:this.obj.name+'简介',
					imageUrl:'https://www.leedong.top/img/11556.png',
					path:'/pages/authorsdetail/index?obj='+JSON.stringify(this.obj)
					
				}
			},
		methods:{
			poetrydetail(t){
				uni.navigateTo({
					url:'/pages/poetrydetail/index?title='+JSON.stringify(t)
				})
			},
			async getAuthos(name){
				const data = await this.$api.authorseach({
					author_name:name
				});
				 this.obj = data.rows[0];
				 this.getList(this.obj.id)
				 
				
			},
			async getAuthors() {
				this.pageNumber += 1;
				this.moreText = '加载中...'
				if (this.pageNumber >= this.totalPage) {
					this.moreText = '已加载全部'
					return;
				}
				const data = await this.$api.authorspoetry({
					authorId: this.obj.id,
					pageNumber: this.pageNumber,
					pageSize: 20
				});
				this.totalPage = Math.ceil(data.total / 10);
				this.list = this.list.concat(data.rows)
			},
			async getList(id){
				this.pageNumber+=1;
				const data = await this.$api.authorspoetry({
					authorId:id,
					pageNumber: this.pageNumber,
					pageSize: 20
				});
					this.totalPage = Math.ceil(data.total / 10);
			this.list=data.rows;
			}

		}
	}
</script>

<style lang="scss">
	.authors{
		width: 100%;
		.authors_details{
			padding: 20px;
			.name{
				
				
				
					.shu {
						height: 20px;
						display: inline-block;
						
						width: 4px;
						vertical-align: middle;
						background-color: #7d8468;
					
				}
				span{
					padding: 5px;
					font-size: 18px;
					color:$color;
				}
			}
			.potry_name{
				margin-top: 10px;
				height: 28px;
				font-size: 14px;
				border-bottom: 1px solid #f5f5f5;
			}
			.more {
				text-align: center;
			
				span {
					font-size: 12px;
					color: #9a8383;
				}
			}
			.content{
				font-size: 15px;
				padding: 5px;
				color: $uni-text-color-grey;
			}
		}
	}
</style>